<?php
Prado::using('System.I18N.core.NumberFormat');
Prado::using('Application.common.common');
class ProductBoxTemplate extends TRepeaterItemRenderer
{
	public function onDataBinding($param)
	{
		parent::onDataBinding($param);
		if (count($this->Data)>0)
		{
			$this->imgProductPhotoThumb->ImageUrl = $this->Request->UrlManagerModule->UrlPrefix."/useruploads/images/product/thumbs/".$this->Data->ThumbnailPath;
		}
		//$this->lblPrice->Text = count($this->Data->Properties)>0?$this->getFormattedValue(($this->Data->Properties[0]->Price)):"$0.00";
		
		/*if ($this->Data)
		{
			if (strlen($this->Data->Brief)>185)
			{
				$this->lblDesc->Text = $this->Data->Brief . "<a style='color:brown;' href='".$this->Service->ConstructUrl("shop.ProductDetail",array("id"=>$this->Data->ID,"alias"=>$this->Data->Alias))."'>...more</a>";
			}
			else if (strlen($this->Data->Description)>0)
			{
				if (strlen($this->Data->Description)>185)
					$this->lblDesc->Text = Common::neatTrim($this->Data->Description,185,"") . "<a style='color:brown;' href='".$this->Service->ConstructUrl("shop.ProductDetail",array("id"=>$this->Data->ID,"alias"=>$this->Data->Alias))."'>...more</a>";
				else $this->lblDesc->Text = $this->Data->Description;
			}
		}*/
	}
	public function getFormattedValue($value,$pattern="c",$currency="USD")
	{
		$formatter = new NumberFormat($this->Application->Globalization->Culture);
		return $formatter->format($value,$pattern,$currency,$this->Application->Globalization->Charset);
	}	

	/*protected function btnAddToCart_Clicked($sender, $param)
	{
		// do add cart here
		try
		{
			$cartTemp = CartTempRecord::finder()->findByPk($this->Session->SessionID);
			if (!($cartTemp instanceof CartTempRecord))
			{
				$cartTemp = new CartTempRecord;
				$cartTemp->SessionID = $this->Session->SessionID;
				if (!$this->User->IsGuest) $cartTemp->UserID = $this->User->ID;
				$cartTemp->save();
			}
			// we should check if user select the same product
			$cartDetail = CartTempDetailRecord::finder()->findBysession_idAndproduct_idAndprop_id($this->Session->SessionID,$this->txtID->Value,$this->cboPropertySelector->SelectedValue);
			$prop = PropertyRecord::finder()->withProduct()->findByPk($this->cboPropertySelector->SelectedValue);
			if ($cartDetail instanceof CartTempDetailRecord)
			{
				$cartDetail->Quantity = $cartDetail->Quantity + $this->cboQuantitySelector->SelectedValue;
			}
			else
			{
				$cartDetail = new CartTempDetailRecord;
				$cartDetail->HashID = md5(uniqid(time()));
				$cartDetail->SessionID = $cartTemp->SessionID;
				if (!$this->User->IsGuest) $cartDetail->UserID = $this->User->ID;
				$cartDetail->ProductID = $this->txtID->Value;
				$cartDetail->Quantity = $this->cboQuantitySelector->SelectedValue;
				if ($prop instanceof PropertyRecord)
				{
					$cartDetail->PropertyID = $prop->ID;
				}
				$cartDetail->CreateDate = time();
			}
			$cartDetail->Subtotal = $cartDetail->Quantity*Common::roundTo($prop->Product->getDiscountPrice($prop->Price));
			
			$cartDetail->save();
			//$this->Response->redirect($this->Service->ConstructUrl("shop.cart.Index"));
			$this->Page->ajaxCart->refreshCart();
		}
		catch(TException $e)
		{
			$this->Page->Notice->Type = UserNoticeType::Error;
			$this->Page->Notice->Text = $this->Application->getModule("message")->translate("UNKNOWN_ERROR");
			try {
				if ($this->Page->categoryMenu) $this->Page->categoryMenu->populateData();
				if (method_exists($this->Page,"populateData")) $this->Page->populateData();
			}
			catch(TException $e) {}
		}
	}*/
}

?>